from django.db import models
from shortuuidfield import ShortUUIDField
from datetime import datetime
from users.models import UserModel


# 留言表
class MessageTable(models.Model):
    GENDER_CHOICES = (
        (u'0', u'未回复'),
        (u'1', u'回复'),
    )
    DEL_GENDER_CHOICES = (
        (u'0', u'未删除'),
        (u'1', u'删除'),
    )
    id = ShortUUIDField(primary_key=True, verbose_name="留言表id")
    content = models.CharField(max_length=255, verbose_name="留言内容")
    create = models.CharField(default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), max_length=20,
                              verbose_name="创建日期")
    status = models.CharField(max_length=2, choices=GENDER_CHOICES, default='0', verbose_name="是否注销")
    del_status = models.CharField(max_length=2, choices=DEL_GENDER_CHOICES, default='0', verbose_name="是否注销")
    user = models.OneToOneField(UserModel, on_delete=models.CASCADE)
    class Meta:
        db_table = 'message'
        verbose_name = '留言表'
        verbose_name_plural = verbose_name


# 回复表
class ReplyTable(models.Model):
    id = ShortUUIDField(primary_key=True, verbose_name="回复表id")
    reply = models.CharField(max_length=255, verbose_name="回复内容")
    recovery_time = models.CharField(default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), max_length=20,
                                     verbose_name="回复日期")
    # 一对一关联
    message = models.OneToOneField(MessageTable, on_delete=models.CASCADE)

    class Meta:
        db_table = 'reply'
        verbose_name = '回复表'
        verbose_name_plural = verbose_name


# 论坛表
class BbsModel(models.Model):
    id = ShortUUIDField(primary_key=True, verbose_name="帖子表id")
    topic = models.CharField(max_length=255, verbose_name="帖子内容")
    commit_time = models.DateTimeField(auto_now_add=True)
    user = models.OneToOneField(UserModel, on_delete=models.CASCADE)

    class Meta:
        db_table = 'bbs'
        verbose_name = '论坛表'
        verbose_name_plural = verbose_name
